package com.example.bakend.mapper;

import com.example.bakend.pojo.Book;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface BookMapper {
    @Select("select * from books")
    List<Book> selectBooks();

    @Select("select * from books where id = #{id}")
    Book selectBook(Integer id);

    @Insert("insert into books (title,author,publish_date,stock_quantity,image,categories_id) values (#{title},#{author},#{publishDate},#{stockQuantity},#{image},#{categoriesId})")
    Integer insertBook(Book book);

    Integer updateBook(Book book);


    List<Book> getBooks(@Param("title") String title,
                        @Param("author") String author,
                        @Param("publishDateBegin") LocalDateTime publishDateBegin,
                        @Param("publishDateEnd") LocalDateTime publishDateEnd);

//    删除类别的同时删除类别下的书
    @Delete("delete from books where categories_id = #{id}")
    Integer deleteBook(Integer id);

    Integer deleteBooks(@Param("ids") List<Integer> ids);


    @Select("select * from books where  categories_id = #{categoriesId}")
    List<Book> getBooksForCategory(Integer categoriesId);



}
